<template>
  <v-container app>
    <v-container>
    <v-form
      ref="form"
    >
      <v-text-field
        v-model="username"
        :counter="50"
        label="姓名"
        required
      ></v-text-field>

      <v-text-field
        v-model="loginname"
        :counter="50"
        label="登录名"
        required
      ></v-text-field>

      <v-btn
        color="success"
        class="mr-4"
        @click="save"
      >
        保存
      </v-btn>

      <v-btn
        color="error"
        class="mr-4"
        @click="back"
      >
        返回
      </v-btn>

    </v-form>
    </v-container>
    <myAlert :dialog="dialog" :msg="msg" @setParam="setParam"></myAlert>
  </v-container>
</template>

<script>
import myAlert from '@/components/common/myAlert'

export default {
  data: () => ({
    userid: '',
    username: '',
    loginname: '',
    dialog: false,
    msg: ''
  }),
  components: {
    myAlert
  },
  methods: {
    queryUser: function () {
      this.axios.post('user/queryUser', 'userid=' + this.userid).then(response => {
        this.username = response.data.username
        this.loginname = response.data.loginname
      })
    },
    save: function () {
      this.axios.post('user/modUser', 'username=' + this.username + '&loginname=' + this.loginname + '&userid=' + this.userid).then(response => {
        if (response.data.nResult === '0') {
          this.$router.replace('userList')
        } else {
          this.dialog = true
          this.msg = response.data.msg
        }
      })
    },
    back: function () {
      this.$router.replace('userList')
    },
    setParam: function (dialog) {
      this.dialog = dialog
    }
  },
  created: function () {
    const user = this.$route.query
    this.userid = user.userid
    this.queryUser()
  }
}
</script>
